Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Imaging with QuickDraw

Previous | Chapter Top | Chapter Contents | Next |

Drawing With Different Foreground Colors

You can set the foreground and background colors using either Color QuickDraw or Palette Manager routines. If your application uses the Palette Manager, it should set the foreground and background colors with the PmForeColor and PmBackColor routines, as described in the chapter "Palette Manager" in Inside Macintosh: Advanced Color Imaging. Otherwise, your application can use the RGBForeColor procedure to set the foreground color, and it can use the RGBBackColor procedure to set the background color. Both of these Color QuickDraw procedures also operate for basic graphics ports created in System 7. (To set the foreground and background colors for basic graphics ports on older versions of system software, use the ForeColor and BackColor procedures described in the chapter "QuickDraw Drawing.")

The RGBForeColor procedure lets you set the foreground color to the best color available on the current graphics device. This changes the color of the "ink" used for drawing. All of the line-drawing, framing, and painting routines described in the chapter "QuickDraw Drawing" (such as LineTo , FrameRect , and PaintPoly ) draw with the foreground color that you specify with RGBForeColor .

Because a pixel pattern already contains color, Color QuickDraw ignores the foreground and background colors when your application draws with a pixel pattern. As described in "Drawing With Pixel Patterns," , you can draw with a pixel pattern by using the PenPixPat procedure to assign a pixel pattern to the graphics pen, by using the BackPixPat procedure to assign a pixel pattern as the background pattern for the current color graphics port, and by using the FillCRect , FillCOval , FillCRoundRect , FillCArc , FillCRgn , and FillCPoly procedures to fill shapes with a pixel pattern.

To specify a foreground color, create an RGBColor record. Listing 4-2 defines two RGBColor records. The first is declared as myDarkBlue , and it's defined with a medium-intensive blue component and with zero-intensity red and green components. The second is declared as myMediumGreen , and it's defined with an intensive green component, a mildly intensive red component, and a very slight blue component.

Listing 2 Changing the foreground color

PROCEDURE MyPaintAndFillColorRects;
VAR
    firstRect, secondRect:          Rect;
    myDarkBlue:                     RGBColor;
    myMediumGreen:                  RGBColor;
BEGIN
        {create dark blue color}
    myDarkBlue.red := $0000;
    myDarkBlue.green := $0000;
    myDarkBlue.blue := $9999;
        {create medium green color}
    myMediumGreen.red := $3206;
    myMediumGreen.green := $9038;
    myMediumGreen.blue := $013D;
    RGBForeColor(myDarkBlue);           {draw with dark blue pen}
    PenMode(patCopy);
    SetRect(firstRect, 20, 20, 70, 70);
    PaintRect(firstRect);                   {paint a dark blue rectangle}
    RGBForeColor(myMediumGreen);            {draw with a medium green pen}
    SetRect(secondRect, 90, 20, 140, 70);
    FillRect(secondRect, ltGray);           {paint a medium green rectangle}
END;

In Listing 4-2 , the RGBColor record myDarkBlue is supplied to the RGBForeColor procedure. The RGBForeColor procedure supplies the rgbFgColor field of the CGrafPort record with this RGBColor record, and it places the closest-matching available color in the fgColor field; the color in the fgColor field is the color actually used as the foreground color.

After using SetRect to create a rectangle, Listing 4-2 calls PaintRect to paint the rectangle. By default, the foreground color is black; by changing the foreground color to dark blue, every pixel that would normally be painted in black is instead painted in dark blue.

Listing 4-2 then changes the foreground color again to the medium green specified in the RGBColor record myMediumGreen . After creating another rectangle, this listing calls FillRect to fill the rectangle with the bit pattern specified by the global variable ltGray . As explained in the chapter "QuickDraw Drawing," this bit pattern consists of widely spaced black pixels that create the effect of gray on black-and-white screens. However, by changing the foreground color, every pixel in the pattern that would normally be painted black is instead drawn in medium green.

The effects of Listing 4-2 are illustrated in the grayscale screen capture shown in Figure 4-9 .

Figure 9 Drawing with two different foreground colors (on a grayscale screen)

If you wish to draw with a color other than the foreground color, you can use the PenPixPat procedure to give the graphics pen a colored pixel pattern that you define, and you can use the FillCRect , FillCRoundRect , FillCOval , FillCArc , FillCPoly , and FillCRgn procedures to fill shapes with colored patterns. The use of these procedures is illustrated in the next section.


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next